package com.yzy.soft.system.controller;

import com.yzy.soft.common.persistence.dao.GooflowMapper;
import com.yzy.soft.system.dto.CreateBackgroundFileDto;
import com.yzy.soft.system.service.CodeGenerateService;
import com.yzy.soft.system.service.FileService;
import com.yzy.soft.system.util.ZipUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

@RestController
@RequestMapping("/createfile")
public class CreateFileController {


    private final static Logger logger= LoggerFactory.getLogger(CreateFileController.class);

    @Autowired
    private CodeGenerateService codeGenerateService;
    @Autowired
    private FileService fileService;
    @Autowired
    private DownloadController ownloaddController;
    @PostMapping(value = "/background",produces = MediaType.APPLICATION_JSON_UTF8_VALUE )
    public String backgroundFile(@RequestBody CreateBackgroundFileDto createBackgroundFileDto,HttpServletResponse response,HttpServletRequest request) {
        logger.info("{}",createBackgroundFileDto);


        List<File> filePaths=codeGenerateService.createFile(createBackgroundFileDto);

        String ff="D:\\AAAAA\\aa";
        try {
            File file=fileService.zipTools(filePaths,ff);

            return file.getPath();
//            ZipUtils.fileStreamToZipStream(file, response);
        } catch (IOException e) {
            e.printStackTrace();
        }
//        ownloaddController.downloadFile(request,response);
        return "";
    }

}
